<?php
	
	class stat_product_monthControl extends skymvc{
		public $sw; 
		public $k;
		public function __construct(){
			
			parent::__construct();
		}
		
		public function onDefault(){
			$k="koudai";
		 
			$where= " k='$k' AND shopid=".SHOPID;
			$start=get('per_page','i');
			$limit=96;
			$url=APPKOUDAI."?m=stat_product_month&k=".$k;
		 
			$kmonth=get('kmonth','h');
			if(!$kmonth){
				$kmonth=date("Ym");
			}
			$where.=" AND kmonth='".$kmonth."'";
			$url.="&kmonth=".$kmonth;
			$option=array(
				"where"=>$where,
				"start"=>$start,
				"limit"=>$limit,			
				"order"=>" kmonth DESC",
			);
			$rscount=true;
			$data=M("stat_product_month")->select($option,$rscount);
				$labels="";
				$moneys="";
				if($data){
					
					foreach($data as $v){
						$productids[]=$v['productid'];
					}	
					if($k=='shop'){
						$products=M("shop_product")->getListByIds($productids);
					}else{
						$products=M("product")->getListByIds($productids);
					}
						 
					foreach($data as $k=>$v){
						$productids[]=$v['productids'];
						$v['title']=$products[$v['productid']]['title'];
						$data[$k]=$v;
					}					
					 
					
				}
				 
			 
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(array(
				"list"=>$data,
				"rscount"=>$rscount,
				"kmonth"=>$kmonth,
				"pagelist"=>$pagelist,
				"labels"=>$labels,
				"moneys"=>$moneys,
				"field"=>$field,
				"total_money"=>$total_money
			));
			$this->smarty->display("stat_product_month/index.html");
		}
		
	}